/*
 * 6.1.cpp
 *
 *  Created on: 2012-5-18
 *      Author: jawinton
 */

/*
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define SIZE 300

static int m[14] = {0, 2, 7, 5, 30, 169, 441, 1872, 7632, 1740, 93313, 459901, 1358657, 2504881}

int main (void) {
	int k, m;
	while (true) {
		cin >> k;
		if (k == 0) break;
		printf("%d\n", m[k]);
	}
	return 0;
}
*/

/*
 * 6.1.cpp
 *
 *  Created on: 2012-5-18
 *      Author: jawinton
 */

#include <cstdio>
#include <cstdlib>

using namespace std;

#define SIZE 300

int n, k;
bool monkeys[SIZE+10];

int nextPt (int cur) {
	while (monkeys[cur] == false) cur = (cur+1)%n;
	cur = (cur+1)%n;
	return cur;
}

int main (void) {
	while (true) {
		scanf("%d", &k);
		if (k == 0) break;
		n = 2*k;
		for (int i=0; i<n; i++) monkeys[i] = true;

		int m = 2;
		while (true) {
			int i, nPt = 0;
			for (i=0; i<k; i++) {
				int nCount = 0;
				while (nCount < m) {
					nPt = nextPt(nPt);
					nCount ++;
				}
				nPt --;
				if (nPt == -1) nPt = n-1;
				monkeys[nPt] = false;
				if (nPt < k) {
					for (int j=0; j<n; j++) monkeys[j] = true;
					break;
				}
			}
			if (i == k) break;
			m++;
		}
		printf("%d\n", m);
	}
	return 0;
}

